var app = angular.module('webapp');

app.controller('LoginController', ['$scope','LoginService', LoginController]);

function LoginController($scope,LoginService){
	$scope.user = {
		userName : 'admin',
		password : '123456'
	};
	$scope.subErr = '';
    $scope.subLogin =  function(){
    	if(!$scope.user.userName){
    		$scope.subErr = 'UserName is required';
    		return;
    	}

    	if(!$scope.user.password){
    		$scope.subErr = 'password  is required';
    		return;
    	}

    	$scope.subErr = '';

        LoginService.getByUser($scope.user).then(function(data){
            if(data.code == 0){
                location.href='/';
            }else{
                $scope.subErr = data.message;
            }
        },function(err){
        	
        });
    };
}